<#include "../../layout.ftl">
<@title>
    <title>字典信息信息</title>
</@title>
<@css>

</@css>
<@layout>
    <div class="container-div">
        <div class="ibox-content">
            <form class="form-horizontal m" id="dicForm" autocomplete="off">
                <input type="hidden" id="id" name="id" value="${id}">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">字典名称：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="dicName" id="dicName" data-rule="required">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">字典编码：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="dicCode" id="dicCode" data-rule="required">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">显示顺序：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="number" name="sortNum" value="1" id="sortNum" data-rule="required">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <input id="remark" name="remark" class="form-control" type="text">
                    </div>
                </div>
                <div class="footerbar">
                    <div class="col-sm-12 col-sm-offset-3">
                        <button class="btn btn-primary" type="submit">
                            <i class="fa fa-check"></i>
                            保存
                        </button>
                        <button class="btn btn-danger" type="button" onclick="cancel()">
                            <i class="fa fa-reply-all"></i>关闭
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</@layout>

<@js>

    <script layout:fragment="script">
        $(function () {
            $('#dicForm').validator({
                stopOnError: false,
                timely: 2,
                theme: "yellow_right",
                valid: function (form) {
                    //console.log(form);
                    jutils.ajaxPost("/admin/dict/saveData", $(form).serialize(), function (res) {
                        if (res.status) {
                            cancel();
                        }
                    });
                },
            });
            loadModel();
        });

        function loadModel() {
            let id = $('#id').val();
            if (jutils.emptyId(id)) {
                return;
            }
            jutils.ajaxGet('/admin/dict/getmodel', { id: id }, function (res) {
                if (res.status) {
                    let model = res.data.model;
                    $('#dicForm').initFormData(model);
                }
            });
        }


        function cancel() {
            jutils.closeDialog();
        }

    </script>
</@js>
